﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BasicDataTypes
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("***** Basic Data Type *****");
            Console.WriteLine();

            LocalVarDeclarations();
            Console.WriteLine();

            NewingDataTypes();
            Console.WriteLine();

            ObjeceFunctionality();
            Console.WriteLine();

            DataTypeFunctionality();
            Console.WriteLine();

            CharFunctionality();
            Console.WriteLine();

            ParseFormStrings();
            Console.WriteLine();

            UseDatesAndTimes();
            Console.ReadLine();

            Console.ReadLine();
        }

        /// <summary>
        /// 声明变量和初始化
        /// </summary>
        private static void LocalVarDeclarations()
        {
            Console.WriteLine("=> Data Declarations:");
            int myInt = 0;
            string myString;
            myString = "This is mycharacter data";
            bool b1 = true, b2 = false, b3 = b1;
            Boolean b4 = false;
            Console.WriteLine("Your data: {0}，{1}，{2}，{3}，{4},{5}", myInt, myString, b1, b2, b3, b4);
            Console.WriteLine();
        }

        /// <summary>
        /// 内建数据类型与new操作符
        /// </summary>
        private static void NewingDataTypes()
        {
            Console.WriteLine("=> Using new to create variables:");
            bool b = new bool();
            int i = new int();
            double d = new double();
            DateTime dt = new DateTime();
            Console.WriteLine("{0},{1},{2},{3}", b, i, d, dt);
            Console.WriteLine();
        }

        /// <summary>
        /// 数据类型的层次结构
        /// </summary>
        private static void ObjeceFunctionality()
        {
            Console.WriteLine("=> System.Object Functionality:");

            Console.WriteLine("12.GetHashCode() = {0}", 12.GetHashCode());
            Console.WriteLine("12.EqualsP(23) = {0}", 12.Equals(23));
            Console.WriteLine("12.ToString = {0}", 12.ToString());
            Console.WriteLine("12.GetType() = {0}", 12.GetType());
            Console.WriteLine();
        }

        /// <summary>
        /// 数值数据类型的成员
        /// </summary>
        private static void DataTypeFunctionality()
        {
            Console.WriteLine("=> Data type Functionality:");

            Console.WriteLine("Max of int: {0}", int.MaxValue);
            Console.WriteLine("Min of int: {0}", int.MinValue);
            Console.WriteLine("Max of Double:{0}", double.MaxValue);
            Console.WriteLine("Min of Double:{0}", double.MinValue);
            Console.WriteLine("double.Epsilon: {0}", double.Epsilon);
            Console.WriteLine("double.PositiveInfinity: {0}", double.PositiveInfinity);
            Console.WriteLine("double.NegativeInfinity: {0}", double.NegativeInfinity);
            Console.WriteLine("bool.FalseString: {0}", bool.FalseString);
            Console.WriteLine("bool.TrueString: {0}", bool.TrueString);

            Console.WriteLine();
        }

        /// <summary>
        /// System.Char的成员
        /// </summary>
        private static void CharFunctionality()
        {
            Console.WriteLine("=> char type Functionality");

            char myChar = 'a';
            Console.WriteLine("char.IsDigit('a'): {0}", char.IsDigit(myChar));
            Console.WriteLine("char.IsLetter('a'): {0}", char.IsLetter(myChar));
            Console.WriteLine("char.IsWhiteSpace('Hello There',5): {0}", char.IsWhiteSpace("Hello There", 5));
            Console.WriteLine("char.IsWhiteSpace('Hello There',6): {0}", char.IsWhiteSpace("Hello There", 6));
            Console.WriteLine("char.IsPunctuation('?'): {0}", char.IsPunctuation('?'));
            Console.WriteLine();
        }

        /// <summary>
        /// 从字符串数据中解析数值
        /// </summary>
        private static void ParseFormStrings()
        {
            Console.WriteLine("=> Data type parsing:");
            bool b = bool.Parse("True");
            Console.WriteLine("Value of b: {0}", b);
            double d = double.Parse("99.884");
            Console.WriteLine("Value of d: {0}", d);
            int i = int.Parse("8");
            Console.WriteLine("Value of i: {0}", i);
            char c = char.Parse("W");
            Console.WriteLine("Value of c: {0}", c);
            Console.WriteLine();
        }

        /// <summary>
        /// System.DateTime与System.Timespan
        /// </summary>
        private static void UseDatesAndTimes()
        {
            Console.WriteLine("=> Dates And Times:");
            DateTime dt = new DateTime(2014, 6, 17);
            Console.WriteLine("The day of {0} is {1}", dt.Date, dt.DayOfWeek);
            dt = dt.AddMonths(2);
            Console.WriteLine("Daylight savings: {0}", dt.IsDaylightSavingTime());

            TimeSpan ts = new TimeSpan(4, 30, 0);
            Console.WriteLine(ts);
            Console.WriteLine(ts.Subtract(new TimeSpan(0, 15, 0)));
            Console.WriteLine();
        }
    }
}
